package com.example.hp.yuejian5.model;



import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.CourseBean;
import com.example.hp.yuejian5.service.CourseService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.hp.yuejian5.other.url.COURSEURL;

public class CourseModel {
    private Retrofit retrofit;
    private CourseService courseService;

    public CourseModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(COURSEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        courseService=retrofit.create(CourseService.class);
    }
    public void courseList(final RetrofitListener listener)
    {
        Call<List<CourseBean>> call=courseService.courselist();
        call.enqueue(new Callback<List<CourseBean>>() {
            @Override
            public void onResponse(Call<List<CourseBean>> call, Response<List<CourseBean>> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<List<CourseBean>> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
